<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>回答列表</title>
<link href="<%=path%>/static/usercss/css/all.css?ehweee43wwweee300" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/ueditor.config.js?123123"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/ueditor.all.js"> </script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script> 
<!--[if IE]>
<script>
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()
</script>
<![endif]-->
<!-- 编辑器样式 -->
<style type="text/css">
	#editor{
		width:960px;
		height:200px;
	}

</style>
</head>
<body>
<jsp:include page="/WEB-INF/web/includ/header.jsp"></jsp:include>
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<section>
<div class="wrap">
  <div id="seach">
    <div id="logo"><a href="http://fenlicx.qinglab.cn" title="垃圾分类查询">分类查询</a></div>
   
  </div>
 
<nav>
    
</nav>

<article class="article">
<div class="comment">
<div class="usinfo"><img src="<%=path %>/static/head_img/${questions.userinfo.headName}" alt="评论者"><span>${questions.userinfo.name}</span> <span><fmt:formatDate pattern="yyyy/MM/dd HH:mm:ss" value="${questions.inputTime}"></fmt:formatDate></span></div>
  <h1>${questions.content}</h1>
<!-- 收藏开始 -->	
<span style="display:inline-block; padding-top:10px;">
 	<img id="removeCollect" style="display:${requestScope.isCollect?'block':'none'};cursor:pointer;" width="20px" src="<%=path%>/static/images/collect.png">
 	<img id="addCollect" style="display:${requestScope.isCollect?'none':'block'};cursor:pointer;" width="20px" src="<%=path%>/static/images/noCollect.png">
</span>
 <!-- 收藏结束 -->
  <span>相关垃圾：${rubbishs.name}</span>

  <div class="commentinput">
    <ul>
     <c:forEach items="${requestScope.questions.answers}" var="answer">
      <li>
        <div class="us"><img src="<%=path %>/static/head_img/${answer.userinfo.headName}" alt="评论者"><span>${answer.userinfo.name}</span> <span><fmt:formatDate pattern="yyyy/MM/dd HH:mm:ss" value="${answer.inputTime}"></fmt:formatDate></span></div>
        <div class="content">
        <p>${answer.content}</p>
         <div class="handle">
         
         <a aa="${answer.id}" id="removePraise" href="javaScript:void(0)" style="display:${answer.isPraise?'block':'none'};" class="active">赞</a>
   		 <a aa="${answer.id}" id="addPraise" href="javaScript:void(0)" style="display:${answer.isPraise?'none':'block'};">否</a>
    		
		    <span id="praiseCount">${answer.praiseCount}</span>
		    
		    <c:if test="${answer.isPick }"><span>已采纳</span></c:if>
		    <c:if test="${sessionScope.userinfo.id == requestScope.questions.userinfo.id}" >
		    
		    <c:if test="${!questions.isSolve }">
		    <input aaa="${answer.id }" type="button" name="isPick" id="isPick" value="采纳">
		    </c:if>
		    </c:if> 
		    
	  	</div>
        </div>
      </li>
      </c:forEach>
      </ul>
    <c:if test="${sessionScope.userinfo.id !=null}">
      <form id="f1" action="<%=path%>/web/question/addAnswer">
      <h1>写下您的回答...</h1>
      <script id="editor" type="text/plain" name="content" ></script>
      <!-- <textarea name="content" cols="50" rows="10" placeholder="写下您的回答..."></textarea> -->
      <input type="hidden" value="${sessionScope.userinfo.id}" name="userinfo.id">
      <input type="hidden" value="${param.questionId}" name="question.id">
      <input type="submit" class="seach_bun" name="button" id="sub" value="提交回答">
      </form>
    </c:if> 
    </div>
</div>

</article>
   </div>
</section>
</div>
<jsp:include page="/WEB-INF/web/includ/footer.jsp"></jsp:include>
</body>
<script type="text/javascript">
$(function(){
	var path = "${pageContext.request.contextPath}"
	
	var ue = UE.getEditor('editor',{toolbars:[['simpleupload','bold','italic','forecolor','strikethrough','horizontal','selectall','time','date','help']],										
		elementPathEnabled:false,
		wordCount:false});
	
	$("#sub").click(function(){
		var content = ue.getContent();;

		if(content!=""){
			$("#f1").submit();
		}else{
			layer.alert("请将所需内容补充完整");	
		}
	});
	
});


</script>
<script type="text/javascript">
var path = "${pageContext.request.contextPath}"
var questionId = ${requestScope.questions.id};
$(function(){
	$("input[id=isPick]").click(function(){
	
		var answerId = $(this).attr("aaa");
		
		
		$.ajax({
			type : "POST",
			url : "<%=path%>/web/userinfo/answerIsPick",
			data : "questionId="+questionId + "&answerId="+answerId,
			dataType:"json",
			success : function() {
				location.href=location.href;
			}
		});
	})
	
})

/*点赞这里找*/
	/*点赞*/
$(function(){
	$("a[id=addPraise]").click(function(){
		
		var answerId = $(this).attr("aa");
		var user = "${sessionScope.userinfo.id}";
		var countLabel = $(this).parent().find("span[id=praiseCount]");
		var praiseCount =parseInt(countLabel.html());

			if(user==""){
				layer.msg("请先登录!");  
			}else{
				$(this).css("display","none");
				$(this).prev().css("display","block")
				$.post("<%=path%>/web/question/addPraise",
						{answerId:answerId},
						function(data){
					
							countLabel.html(praiseCount+1);
				});
			}
			
			return false;
		
	});
	/*取消点赞*/
	$("a[id=removePraise]").click(function(){
		
		var answerId = $(this).attr("aa");
		var user = "${sessionScope.userinfo.id}"
		var countLabel = $(this).parent().find("span[id=praiseCount]");
		var praiseCount =parseInt(countLabel.html());
			if(user==""){
				layer.msg("请先登录!");  
			}else{
				$(this).next().css("display","block");
				$(this).css("display","none")
				$.post(path+"/web/question/removePraise",
						{answerId:answerId},
						function(data){
						
						countLabel.html(praiseCount-1);
				}.bind(this));
			}
		
	});
		
	
})

		$(function() {
			$("#seachBySolr").click(function() {
			
				
			var keyword = $(this).prev().val();
			
			location.href=path+"/web/seachQuestion?keyword="+keyword;  
		})
	})
	
	/*收藏这里找*/	
	/*收藏*/
	
	$("#addCollect").click(function(){
		var user = "${sessionScope.userinfo.id}"
			if(user==""){
				layer.msg("请先登录!");  
			}else{
				$("#addCollect").css("display","none");
				$("#removeCollect").css("display","block")
				$.post(path+"/web/question/addCollect",
						{questionId:questionId}
						);
			}
		
	});
	/*取消收藏*/
	$("#removeCollect").click(function(){
		var user = "${sessionScope.userinfo.id}"
			if(user==""){
				layer.msg("请先登录!");  
			}else{
				$("#addCollect").css("display","block");
				$("#removeCollect").css("display","none")
				$.post(path+"/web/question/removeCollect",
						{questionId:questionId});
			}
		
	});
</script>

</html>
